package io.adrainty.bolee.insurance.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.adrainty.bolee.framework.commons.basic.ResultDTO;
import io.adrainty.bolee.framework.commons.utils.ResultDTOUtil;
import io.adrainty.bolee.insurance.models.entity.ConditionEntity;
import io.adrainty.bolee.insurance.service.IConditionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>ConditionController</p>
 *
 * @author AdRainty
 * @version V1.0.0
 * @description 筛选项管理
 * @since 2025/8/11 11:19:41
 */

@Tag(name = "筛选项管理")
@RestController
@RequestMapping("/condition")
public class ConditionController {

    @Resource
    private IConditionService conditionService;

    @PostMapping("/page/{pageNum}/{pageSize}")
    @Operation(summary = "分页获取保障项")
    public ResultDTO<IPage<ConditionEntity>> findConditionPage(@PathVariable("pageNum") Integer pageNum,
                                                               @PathVariable("pageSize") Integer pageSize,
                                                               @RequestBody ConditionEntity searchDTO) {
        IPage<ConditionEntity> pageResult = conditionService.findConditionPage(pageNum, pageSize, searchDTO);
        return ResultDTOUtil.success(pageResult);
    }

    @PostMapping("/list")
    @Operation(summary = "获取保障项列表")
    public ResultDTO<List<ConditionEntity>> findConditionList(@RequestBody ConditionEntity entity) {
        List<ConditionEntity> list = conditionService.findConditionList(entity);
        return ResultDTOUtil.success(list);
    }

    @PutMapping
    @Operation(summary = "创建保障项")
    public ResultDTO<ConditionEntity> createCondition(@RequestBody ConditionEntity entity) {
        ConditionEntity result = conditionService.createCondition(entity);
        return ResultDTOUtil.success(result);
    }

    @PatchMapping
    @Operation(summary = "修改保障项")
    public ResultDTO<Boolean> updateCondition(@RequestBody ConditionEntity entity) {
        Boolean result = conditionService.updateCondition(entity);
        return ResultDTOUtil.success(result);
    }

    @DeleteMapping
    @Operation(summary = "删除保障项")
    public ResultDTO<Boolean> deleteSafeguard(@RequestBody ConditionEntity entity) {
        Boolean result = conditionService.deleteCondition(Arrays.stream(entity.getCheckedIds()).toList());
        return ResultDTOUtil.success(result);
    }

}
